package com.staka.website.pages.apartment;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.staka.website.beans.ApartmentBean;
import com.staka.website.interfaces.Apartment;
import com.staka.website.service.Apartments;


public class AddApartment {
	
	@Property
	@Persist ("flash")
	private String message;
	
	@Property
	@Persist ("flash")
	private Apartment apartment;
	
	@Inject
	private Apartments apartments;
	
	@SetupRender
	public void createObject() {
		apartment = new ApartmentBean();
	}
	void onSuccess(){
		if (this.apartment.getName() != null) {
			this.apartments.save(apartment);
			this.message = "Uspjesno ste dodali apartman "+this.apartment.getName();
		} else {
			this.message = "Greska, molimo Vas pokusajte ponovo.";
		}
	}
}
